package com.zbbt.sportslottery.util;

import java.io.File;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;

import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.media.QQShareContent;
import com.umeng.socialize.media.QZoneShareContent;
import com.umeng.socialize.media.SinaShareContent;
import com.umeng.socialize.media.TencentWbShareContent;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.SinaSsoHandler;
import com.umeng.socialize.sso.UMQQSsoHandler;
import com.umeng.socialize.weixin.controller.UMWXHandler;
import com.umeng.socialize.weixin.media.CircleShareContent;
import com.umeng.socialize.weixin.media.WeiXinShareContent;
import com.zbbt.sportslottery.app.Constant;

/**
 * 
 * @ClassName: UmengShare
 * @Description: 友盟分享
 * @author：WWH
 * @version V1.0
 */
public class UmengShare {
	private Activity myactivity;
	public final static UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share");

	public UmengShare(Activity context) {
		myactivity = context;
		Init();
	}

	private void Init() {
		// TODO Auto-generated method stub
		// 首先在您的Activity中添加如下成员变量
		QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(myactivity, "1103505320", "5ISLnun40Oz7vBQh");
		qZoneSsoHandler.addToSocialSDK();
		mController.getConfig().setSsoHandler(new SinaSsoHandler());
		// 添加微信平台
		UMWXHandler wxHandler = new UMWXHandler(myactivity, "wxcfe8680e640e16bd",
				"0115146c23a9f03722f29afebbd672cc");
		wxHandler.addToSocialSDK();
		// 添加微信朋友圈
		UMWXHandler wxCircleHandler = new UMWXHandler(myactivity, "wxcfe8680e640e16bd",
				"0115146c23a9f03722f29afebbd672cc");
		wxCircleHandler.setToCircle(true);
		wxCircleHandler.addToSocialSDK();

		UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(myactivity, "1103505320", "5ISLnun40Oz7vBQh");
		qqSsoHandler.addToSocialSDK();
	}

	public void openshareimg(String imageUrl, Bitmap bitmap) {
		// 设置微信好友分享内容
		WeiXinShareContent weixinContent = new WeiXinShareContent();
		SinaShareContent sinasharecontext = new SinaShareContent();
		CircleShareContent circleMedia = new CircleShareContent();
		QQShareContent qqShareContent = new QQShareContent();
		TencentWbShareContent tencentwb = new TencentWbShareContent();
		QZoneShareContent qzone = new QZoneShareContent();
		// 设置分享文字
		qzone.setShareContent("福建体彩");
		// 设置分享内容的标题
		qzone.setTitle("福建体彩");
		if (imageUrl != null && !imageUrl.equals("http://www.zgtcb.com")) {

		} else {
			imageUrl = "http://web.zgtcb.com/img/icon200.png";
		}
		// 设置分享图片
		sinasharecontext.setShareImage(new UMImage(myactivity, bitmap));
		// 设置分享图片
		tencentwb.setShareImage(new UMImage(myactivity, bitmap));
		// 设置分享图片
		weixinContent.setShareImage(new UMImage(myactivity, bitmap));
		// 设置分享图片
		qqShareContent.setShareImage(new UMImage(myactivity, bitmap));
		circleMedia.setShareImage(new UMImage(myactivity, bitmap));
		// 设置分享图片
		qzone.setShareImage(new UMImage(myactivity, imageUrl));
		mController.setShareMedia(tencentwb);
		mController.setShareMedia(qzone);
		mController.setShareMedia(qqShareContent);
		mController.setShareMedia(circleMedia);
		mController.setShareMedia(weixinContent);
		mController.setShareMedia(sinasharecontext);
		mController.openShare(myactivity, false);
	}

	public void openshare(String url, String summaryTx, String shareTitle, String imageUrl, int shareint) {
		String loadurl = url + "?app_name=fjtc";
		// 设置新浪好友分享
		SinaShareContent sinasharecontext = new SinaShareContent();
		if (summaryTx.length() > 100) {
			// 设置分享文字
			sinasharecontext.setShareContent(summaryTx.substring(0, 100) + "..." + url);
		} else {
			sinasharecontext.setShareContent(summaryTx + url);
		}
		// 设置title
		sinasharecontext.setTitle(shareTitle + url);
		// 设置分享内容跳转URL
		sinasharecontext.setTargetUrl(loadurl);

		// 设置微信好友分享内容
		WeiXinShareContent weixinContent = new WeiXinShareContent();
		// 设置分享文字
		weixinContent.setShareContent(summaryTx);
		// 设置title
		weixinContent.setTitle(shareTitle);
		// 设置分享内容跳转URL
		weixinContent.setTargetUrl(loadurl);

		// 设置朋友圈
		CircleShareContent circleMedia = new CircleShareContent();
		circleMedia.setShareContent(summaryTx);
		// 设置朋友圈title
		circleMedia.setTitle(shareTitle);
		circleMedia.setTargetUrl(loadurl);

		// QQ
		QQShareContent qqShareContent = new QQShareContent();
		// 设置分享文字
		qqShareContent.setShareContent(summaryTx);
		// 设置分享title
		qqShareContent.setTitle(shareTitle);

		// 设置点击分享内容的跳转链接
		qqShareContent.setTargetUrl(loadurl);
		// qq空间
		QZoneShareContent qzone = new QZoneShareContent();
		// 设置分享文字
		qzone.setShareContent(summaryTx);
		// 设置点击消息的跳转URL
		qzone.setTargetUrl(loadurl);
		// 设置分享内容的标题
		qzone.setTitle(shareTitle);
		// 腾讯微博
		TencentWbShareContent tencentwb = new TencentWbShareContent();
		// 设置分享文字
		tencentwb.setShareContent(summaryTx + loadurl);
		// 设置点击消息的跳转URL
		tencentwb.setTargetUrl(loadurl);
		// 设置分享内容的标题
		tencentwb.setTitle(shareTitle + loadurl);
		if (imageUrl != null && !imageUrl.equals("http://www.zgtcb.com")) {

		} else {
			imageUrl = "http://web.zgtcb.com/img/icon200.png";
		}
		// 设置分享图片
		sinasharecontext.setShareImage(new UMImage(myactivity, imageUrl));
		// 设置分享图片
		tencentwb.setShareImage(new UMImage(myactivity, imageUrl));
		// 设置分享图片
		weixinContent.setShareImage(new UMImage(myactivity, imageUrl));
		// 设置分享图片
		qqShareContent.setShareImage(new UMImage(myactivity, imageUrl));
		circleMedia.setShareImage(new UMImage(myactivity, imageUrl));
		// 设置分享图片
		qzone.setShareImage(new UMImage(myactivity, imageUrl));

		mController.setShareMedia(tencentwb);
		mController.setShareMedia(qzone);
		mController.setShareMedia(qqShareContent);
		mController.setShareMedia(circleMedia);
		mController.setShareMedia(weixinContent);
		mController.setShareMedia(sinasharecontext);
		mController.openShare(myactivity, false);
		switch (shareint) {
		case 1:
			UmengUtil.onEvent(myactivity, Constant.UMENG_NEWS_SHARE);
			break;
		case 2:
			UmengUtil.onEvent(myactivity, Constant.UMENG_FIND_SHARE);
			break;
		default:
			break;
		}

	}
}
